﻿package com.tudou.home.newskin.panel
{
    import com.tudou.consts.*;
    import com.tudou.cookie.*;
    import com.tudou.home.consts.*;
    import com.tudou.home.newskin.buttons.*;
    import com.tudou.home.newskin.containers.*;
    import com.tudou.home.newskin.events.*;
    import com.tudou.home.newskin.interfaces.*;
    import com.tudou.skin.*;
    import com.tudou.utils.*;
    import flash.display.*;
    import flash.events.*;

    public class ControlPanel extends Sprite implements IPlayer, ITime, IVolume, IVideoSize, IRate, IProgress, IFullscreen, IExpand, IBrightness, IPlayList, ITransform, IButtonState, IPreviewer, IVideoAudio, ISetting, IMove, ISkipHeadTail
    {
        private var rExpandSlip:DisplayObject;
        private var volume:Volume;
        private var timeInfo:TimeSprite;
        private var videoSize:VideoSize;
        private var playTime:Number;
        private var playPause:PlayPauseButton;
        private var rPreNextSpriteSlip:DisplayObject;
        private var rVideoSizeSlip:DisplayObject;
        private var prevNextSprite:PrevNextSprite;
        private var progress:Progress;
        private var background:DisplayObject;
        private var goHeight:uint;
        private var rPlayPauseSlip:DisplayObject;
        private var totalTime:Number;
        private var freezeSprie:Sprite;
        private var isPlayList:Boolean;
        private var rBrightnessSlip:DisplayObject;
        private var brightness:Brightness;
        private var fastBackward:InteractiveObject;
        private var isExpand:Boolean;
        private var isFullscreen:Boolean;
        private var rVolumeSlip:DisplayObject;
        private var expand:ExpandButton;
        private var fullscreen:FullscreenButton;
        private var goWidth:uint;
        private var fastForward:InteractiveObject;
        private var rate:Rate;

        public function ControlPanel()
        {
            background = new ControlPanelMC();
            addChild(background);
            fastBackward = new FastBackwardBTN();
            fastBackward.y = 4;
            addChild(fastBackward);
            fastForward = new FastForwardBTN();
            fastForward.y = 4;
            addChild(fastForward);
            progress = new Progress();
            progress.y = 5;
            addChild(progress);
            var _loc_1:int = -2;
            playPause = new PlayPauseButton();
            playPause.y = background.height - playPause.height + _loc_1;
            addChild(playPause);
            timeInfo = new TimeSprite();
            timeInfo.y = playPause.y + 3;
            addChild(timeInfo);
            rate = new Rate(RateType.P256, false);
            rate.y = int(background.height - rate.showHeight + _loc_1);
            addChild(rate);
            fullscreen = new FullscreenButton();
            fullscreen.y = background.height - fullscreen.height + _loc_1;
            addChild(fullscreen);
            expand = new ExpandButton();
            expand.y = int(background.height - expand.height + _loc_1);
            addChild(expand);
            videoSize = new VideoSize();
            videoSize.y = int(background.height - videoSize.showHeight + _loc_1);
            addChild(videoSize);
            brightness = new Brightness();
            brightness.y = background.height - brightness.showHeight + _loc_1;
            addChild(brightness);
            volume = new Volume();
            volume.y = background.height - volume.height - 5;
            addChild(volume);
            var _loc_2:* = playPause.y;
            rPlayPauseSlip = new SlipBarMC();
            rPlayPauseSlip.y = _loc_2;
            addChild(rPlayPauseSlip);
            rVolumeSlip = new SlipBarMC();
            rVolumeSlip.y = _loc_2;
            addChild(rVolumeSlip);
            rBrightnessSlip = new SlipBarMC();
            rBrightnessSlip.y = _loc_2;
            addChild(rBrightnessSlip);
            rVideoSizeSlip = new SlipBarMC();
            rVideoSizeSlip.y = _loc_2;
            addChild(rVideoSizeSlip);
            rExpandSlip = new SlipBarMC();
            rExpandSlip.y = _loc_2;
            addChild(rExpandSlip);
            freezeSprie = new FreezeSprite(fullscreen.width + 2, fullscreen.height + 2);
            addChild(freezeSprie);
            init();
            initListeners();
            return;
        }// end function

        public function showPreview() : void
        {
            progress.showPreview();
            return;
        }// end function

        public function setLoaded(param1:Number) : void
        {
            progress.setLoaded(param1);
            return;
        }// end function

        private function initListeners() : void
        {
            fastBackward.addEventListener(MouseEvent.CLICK, fastHlr);
            fastForward.addEventListener(MouseEvent.CLICK, fastHlr);
            return;
        }// end function

        private function init() : void
        {
            freezeSprie.visible = false;
            rate.visible = false;
            isPlayList = false;
            goTransform(PlayerConsts.CONTORL_DEFAULT_WIDTH, PlayerConsts.CONTROL_DEFAULT_HEIGTH, false);
            return;
        }// end function

        public function getVolume() : Number
        {
            return volume.getVolume();
        }// end function

        public function setVolume(param1:Number) : void
        {
            volume.setVolume(param1);
            return;
        }// end function

        public function playing() : void
        {
            playPause.playing();
            return;
        }// end function

        public function paused() : void
        {
            playPause.paused();
            return;
        }// end function

        public function getBrightness() : Number
        {
            return brightness.getBrightness();
        }// end function

        public function getIndex() : int
        {
            return 0;
        }// end function

        public function loading() : void
        {
            playPause.loading();
            progress.setStarted(0);
            progress.setPlayed(0);
            progress.setLoaded(0);
            progress.setPlayTime(0);
            progress.setTotalTime(0);
            return;
        }// end function

        public function setBrightness(param1:Number) : void
        {
            brightness.setBrightness(param1);
            return;
        }// end function

        public function set freeze(param1:Boolean) : void
        {
            freezeSprie.visible = param1;
            return;
        }// end function

        public function getRate() : int
        {
            return rate ? (rate.getRate()) : (0);
        }// end function

        public function addVideo(param1:DisplayObject) : void
        {
            progress.addVideo(param1);
            return;
        }// end function

        public function completed() : void
        {
            playPause.completed();
            return;
        }// end function

        public function getVideoSize() : int
        {
            return videoSize.getVideoSize();
        }// end function

        public function goTransform(param1:uint, param2:uint, param3:Boolean) : void
        {
            goWidth = param1;
            goHeight = param2;
            this.isFullscreen = param3;
            background.width = param1;
            var _loc_4:int = -1;
            fastBackward.x = 6;
            fastForward.x = background.width - fastForward.width - 6;
            var _loc_5:uint = 6;
            progress.x = fastBackward.x + fastBackward.width + _loc_5;
            var _loc_6:* = fastForward.x - fastBackward.x - fastBackward.width - 2 * _loc_5;
            progress.goTransform(_loc_6, 0, param3);
            playPause.x = 2;
            rPlayPauseSlip.x = int(playPause.x + playPause.width);
            if (isPlayList)
            {
                prevNextSprite.x = int(rPlayPauseSlip.x + rPlayPauseSlip.width + _loc_4);
                rPreNextSpriteSlip.x = int(prevNextSprite.x + prevNextSprite.width);
                timeInfo.x = int(rPreNextSpriteSlip.x + rPreNextSpriteSlip.width + _loc_4);
            }
            else
            {
                timeInfo.x = int(rPlayPauseSlip.x + rPlayPauseSlip.width + _loc_4);
            }
            if (rate)
            {
                rate.x = int(timeInfo.x + timeInfo.width + _loc_4);
            }
            fullscreen.x = int(background.width - fullscreen.width - 1);
            rExpandSlip.x = int(fullscreen.x - rExpandSlip.width - _loc_4);
            expand.x = int(rExpandSlip.x - expand.width + 1);
            rVideoSizeSlip.x = int(expand.x - rVideoSizeSlip.width - _loc_4);
            videoSize.x = int(rVideoSizeSlip.x - videoSize.width + 1);
            rBrightnessSlip.x = int(videoSize.x - rBrightnessSlip.width - _loc_4);
            brightness.x = int(rBrightnessSlip.x - brightness.width + 1);
            rVolumeSlip.x = int(brightness.x - rVolumeSlip.width - _loc_4);
            volume.x = int(rVolumeSlip.x - volume.showWidth);
            freezeSprie.width = param1;
            addChild(freezeSprie);
            return;
        }// end function

        public function setPreviewer(param1:DisplayObject) : void
        {
            progress.setPreviewer(param1);
            return;
        }// end function

        public function setRate(param1:int) : void
        {
            if (rate)
            {
                rate.setRate(param1);
            }
            if (!isFullscreen && !isExpand && param1 == RateType.ORIGINAL)
            {
                dispatchEvent(new SkinEvent(SkinEvent.SET_EXPAND, true));
            }
            return;
        }// end function

        public function exitFullscreen() : void
        {
            fullscreen.exitFullscreen();
            videoSize.dispatchEvent(new SkinEvent(SkinEvent.SET_VIDEO_SIZE, VideoSizeType.NORMAL));
            return;
        }// end function

        public function setPlayList(param1:Array) : void
        {
            if (param1 && param1.length > 0)
            {
                isPlayList = true;
                prevNextSprite = new PrevNextSprite();
                prevNextSprite.y = playPause.y + 2;
                prevNextSprite.setPlayList(param1);
                addChild(prevNextSprite);
                rPreNextSpriteSlip = new SlipBarMC();
                rPreNextSpriteSlip.y = playPause.y;
                addChild(rPreNextSpriteSlip);
            }
            return;
        }// end function

        public function setRateSetting(param1:RateSettingData) : void
        {
            rate.setRateSetting(param1);
            return;
        }// end function

        public function getMute() : Boolean
        {
            return volume.getMute();
        }// end function

        public function setIndex(param1:int) : void
        {
            prevNextSprite.setIndex(param1);
            return;
        }// end function

        public function setSkipHeadTailValue(param1:Number, param2:Number) : void
        {
            progress.setSkipHeadTailValue(param1, param2);
            return;
        }// end function

        public function isDragging() : Boolean
        {
            return progress.isDragging();
        }// end function

        public function setExpand(param1:Boolean) : void
        {
            isExpand = param1;
            expand.setExpand(param1);
            return;
        }// end function

        public function setSkipSeting(param1:SkipSettingData) : void
        {
            rate.setSkipSeting(param1);
            return;
        }// end function

        public function ready() : void
        {
            playPause.ready();
            expand.show();
            return;
        }// end function

        public function hasSkipHeadTail(param1:Boolean) : void
        {
            progress.hasSkipHeadTail(param1);
            return;
        }// end function

        public function getPlayHead() : Number
        {
            return progress.getPlayHead();
        }// end function

        public function setMute(param1:Boolean) : void
        {
            volume.setMute(param1);
            return;
        }// end function

        public function buffering() : void
        {
            playPause.buffering();
            return;
        }// end function

        public function setStarted(param1:Number) : void
        {
            progress.setStarted(param1);
            return;
        }// end function

        public function enterFullscreen() : void
        {
            fullscreen.enterFullscreen();
            videoSize.dispatchEvent(new SkinEvent(SkinEvent.SET_VIDEO_SIZE, VideoSizeType.NORMAL));
            return;
        }// end function

        public function isAudio(param1:Boolean) : void
        {
            progress.isAudio(param1);
            return;
        }// end function

        public function canMoveOut() : Boolean
        {
            return !rate.selected && !brightness.selected && progress.canMoveOut();
        }// end function

        public function setMaxRate(param1:int, param2:Boolean) : void
        {
            var _loc_3:* = rate.y;
            removeChild(rate);
            rate = new Rate(param1, param2);
            rate.y = _loc_3;
            var _loc_4:* = getChildIndex(timeInfo);
            addChildAt(rate, (_loc_4 + 1));
            rate.selected = false;
            goTransform(goWidth, goHeight, isFullscreen);
            return;
        }// end function

        public function setPlayTime(param1:Number) : void
        {
            playTime = param1;
            progress.setPlayTime(param1);
            timeInfo.setPlayTime(param1);
            return;
        }// end function

        public function move(param1:Number) : void
        {
            progress.move(param1);
            return;
        }// end function

        public function setPlayed(param1:Number) : void
        {
            progress.setPlayed(param1);
            return;
        }// end function

        public function setVideoSize(param1:int) : void
        {
            videoSize.setVideoSize(param1);
            return;
        }// end function

        private function fastHlr(event:MouseEvent) : void
        {
            var _loc_2:Number = NaN;
            if (event.target == fastBackward)
            {
                _loc_2 = -10;
            }
            else if (event.target == fastForward)
            {
                _loc_2 = 10;
            }
            var _loc_3:* = (playTime + _loc_2) / totalTime;
            dispatchEvent(new SkinEvent(SkinEvent.END_SEEK, MathUtil.unit(_loc_3)));
            return;
        }// end function

        public function setTotalTime(param1:Number) : void
        {
            totalTime = param1;
            progress.setTotalTime(param1);
            timeInfo.setTotalTime(param1);
            return;
        }// end function

    }
}

class FreezeSprite extends Sprite
{
    private var holeWidth:uint;
    private var holeHeight:uint;

    function FreezeSprite(param1:uint, param2:uint)
    {
        this.holeWidth = param1;
        this.holeHeight = param2;
        return;
    }// end function

    override public function set width(param1:Number) : void
    {
        var _loc_2:* = PlayerConsts.CONTROL_DEFAULT_HEIGTH - holeHeight;
        graphics.clear();
        graphics.beginFill(0, NewSkinConsts.FREEZE_ALPHA);
        graphics.drawRect(0, 0, param1, _loc_2);
        graphics.drawRect(0, _loc_2, param1 - holeWidth, holeHeight);
        return;
    }// end function

}

